package com.zmp.kotlinnote

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
import java.text.SimpleDateFormat
import java.util.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        XmlParseTools.parseXml(this)
        // Example of a call to a native method
//        sample_text.text = stringFromJNI()
        sample_text.initSvg(R.raw.svg1)
//        sample_text2.initSvg(R.raw.svg2)
        sample_text3.initSvg(R.raw.svg3, isCanAnimal = true, isCanAgain = true)
//        sample_text4.initSvg(R.raw.svg30)
    }

    fun getTime(): CharSequence {
        val currentTimeMillis = System.currentTimeMillis()
        val simpleDateFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
        return simpleDateFormat.format(currentTimeMillis)
    }

    fun click3(view: View) {
//        sample_text3.pauseOrRestart = !sample_text3.pauseOrRestart
        println("click1:${getTime()}")
        val async = GlobalScope.async(context = Dispatchers.IO, start = CoroutineStart.LAZY) {
            println("IO:${getTime()}")
            println("IO:${getTime()}")
            delay(1000)
            "AAA";
        }
        GlobalScope.launch(Dispatchers.Main) {
            println("Main:${async.await()}--${getTime()}${Thread.currentThread().name}")
        }
        Thread.sleep(1000)
        println("click3:${getTime()}")
        Thread.sleep(1000)
        println("click3:${getTime()}")
        Thread.sleep(1000)
        println("click3:${getTime()}")
    }


    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    external fun stringFromJNI(): String

    companion object {

        // Used to load the 'native-lib' library on application startup.
        init {
            System.loadLibrary("native-lib")
        }
    }
}
